package com.oa.demo.common.handler;



import com.oa.demo.common.entity.BaseResponse;
import com.oa.demo.common.utils.OaUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 资源服务器的 401权限异常统一处理
 * @author 孔德成
 * @date 2020/11/24 16:38
 */
@Slf4j
public class BaseAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        BaseResponse febsResponse = new BaseResponse();
           OaUtils.makeResponse(
                   response, MediaType.APPLICATION_JSON_VALUE,
                   HttpServletResponse.SC_UNAUTHORIZED,
                   febsResponse.message("token无效"));
    }
}
